# -*- coding: utf-8 -*-
"""
大乐透历史开奖数据爬虫
使用极速数据API抓取大乐透开奖数据
"""

from typing import List, Dict, Optional
from loguru import logger

from .jisu_spider import JisuLotterySpider


class DLTSpider(JisuLotterySpider):
    """大乐透爬虫 - 基于极速数据API"""
    
    def __init__(self):
        super().__init__('dlt')
    
    def validate_numbers(self, numbers: str) -> bool:
        """验证大乐透号码格式
        
        Args:
            numbers: 号码字符串，格式如 "01,02,03,04,05,06,07"
            
        Returns:
            是否有效
        """
        try:
            parts = numbers.split(',')
            if len(parts) != 7:  # 5前区+2后区
                return False
            
            # 验证前区号码（1-35）
            front_numbers = [int(x) for x in parts[:5]]
            if not all(1 <= x <= 35 for x in front_numbers):
                return False
            
            # 验证后区号码（1-12）
            back_numbers = [int(x) for x in parts[5:]]
            if not all(1 <= x <= 12 for x in back_numbers):
                return False
            
            return True
            
        except (ValueError, IndexError):
            return False


if __name__ == '__main__':
    # 测试代码
    from loguru import logger
    logger.add("../logs/dlt_spider.log", rotation="1 day", retention="30 days")
    
    spider = DLTSpider()
    result = spider.run()
    logger.info(f"爬取结果: {result}")